#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <glib.h>

#define MAX_NUM 10000

int create_one(char* file_name,char *s)
{
	int f;
	mode_t f_attr;
	f_attr=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
	f=open(file_name,O_RDWR | O_CREAT,f_attr);
	if(f==-1)
	{
		printf("创建%s出错\n",file_name);	
	}else{
		write(f,s,strlen(s));
		close(f);
	}
	return 0;
}

GString* one_mil()
{
	GString *s;
	s = g_string_new("");
	for(int i=0;i<MAX_NUM;i++)
	{
		for(int i=0;i<5;i++)
		{
			g_string_append_printf(s,"%d",rand() % MAX_NUM + 1);
			g_string_append(s,"\t");
		}
		g_string_append(s,"\n");
	}	
	return s;
}

int main(){
	GString *s;
	for(int i=0;i<MAX_NUM;i++){
		s = g_string_new("out/r_");
		g_string_append_printf(s,"%d",i);		
		GString *s1 = one_mil();
		create_one(s->str,s1->str);
		g_string_free(s,TRUE);
		g_string_free(s1, TRUE);
	}
	return 0;	
}
